package com.smartleanx.module.hrm.controller.admin.examine.examineFlowPerformance;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.CommonResult;
import com.smartleanx.framework.common.util.object.BeanUtils;
import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.framework.excel.core.util.ExcelUtils;

import com.smartleanx.framework.operatelog.core.annotations.OperateLog;
import static com.smartleanx.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.smartleanx.module.hrm.controller.admin.examine.examineFlowPerformance.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineFlowPerformance.ExamineFlowPerformanceDO;
import com.smartleanx.module.hrm.service.examine.examineFlowPerformance.ExamineFlowPerformanceService;

@Tag(name = "管理后台 - 考核流程中间")
@RestController
@RequestMapping("/hrm/examineFlowPerformance")
@Validated
public class ExamineFlowPerformanceController {

    @Resource
    private ExamineFlowPerformanceService examineFlowPerformanceService;

    @PostMapping("/create")
    @Operation(summary = "创建考核流程中间")
    @PreAuthorize("@ss.hasPermission('hrm:examine-flow-performance:create')")
    public CommonResult<Integer> createExamineFlowPerformance(@Valid @RequestBody ExamineFlowPerformanceSaveReqVO createReqVO) {
        return success(examineFlowPerformanceService.createExamineFlowPerformance(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新考核流程中间")
//    @PreAuthorize("@ss.hasPermission('hrm:examine-flow-performance:update')")
    public CommonResult<Boolean> updateExamineFlowPerformance(@Valid @RequestBody JSONObject param) {
        examineFlowPerformanceService.updateExamineFlowPerformance(param);
        return success(true);
    }

    @GetMapping("/delete")
//    @Operation(summary = "删除考核流程中间")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('hrm:examine-flow-performance:delete')")
    public CommonResult<Boolean> deleteExamineFlowPerformance(@RequestParam("id") Integer id,@RequestParam("fileId") Integer fileId) {
        examineFlowPerformanceService.deleteExamineFlowPerformance(id,fileId);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得考核流程中间")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('hrm:examine-flow-performance:query')")
    public CommonResult<ExamineFlowPerformanceRespVO> getExamineFlowPerformance(@RequestParam("id") Integer id) {
        ExamineFlowPerformanceDO examineFlowPerformance = examineFlowPerformanceService.getExamineFlowPerformance(id);
        return success(BeanUtils.toBean(examineFlowPerformance, ExamineFlowPerformanceRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得考核流程中间分页")
    @PreAuthorize("@ss.hasPermission('hrm:examine-flow-performance:query')")
    public CommonResult<List<ExamineFlowPerformanceDO>> getExamineFlowPerformancePage(@RequestParam("examineId") Integer examineId) {
        List<ExamineFlowPerformanceDO> list = examineFlowPerformanceService.getExamineFlowPerformanceList(examineId);
        return success(list);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出考核流程中间 Excel")
//    @PreAuthorize("@ss.hasPermission('hrm:examine-flow-performance:export')")
//    @OperateLog(type = EXPORT)
//    public void exportExamineFlowPerformanceExcel(@Valid ExamineFlowPerformancePageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<ExamineFlowPerformanceDO> list = examineFlowPerformanceService.getExamineFlowPerformanceList(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "考核流程中间.xlsx", "数据", ExamineFlowPerformanceRespVO.class,
//                        BeanUtils.toBean(list, ExamineFlowPerformanceRespVO.class));
//    }






}